<?php

require_once "facebook/facebook.php";

class My_Facebook{
    protected $facebook;
    public function __construct()
    {
    	$fb_config = array(
				'appId'  => '676793862388399', //APP_ID và SECRET_KEY 2 biến này bạn đã define trong constants nên sử dụng rất dễ dàng
				'secret' => '2507198ae1df43e6e55956ef5570fefe', 
				'cookie' => TRUE,
		);
    	$this->facebook = new Facebook($fb_config);
    }
    public function getUser(){
    	
    	$fbuser =  $this->facebook->getUser();
    	return  $fbuser;
    }
    public function user_profile(){
        $fbuser =  $this->facebook->getUser();
        if ($fbuser && !empty($fbuser)) {
            //var_dump($fbuser);
        	try {
        		$user_profile = $this->facebook->api('/me');
        		//var_dump($user_profile);die();
        		return $user_profile;
        	}
        	catch (Exception $e) {
        		echo  $e->getMessage();
        		return false;
        		exit();
        	}
        	
        }else {
            $vpb_login_url = $this->facebook->getLoginUrl(array('scope' => 'email, user_birthday, user_location, user_photos', 'redirect_uri' => _BASE_URL.'/user/auth/loginfb'));
            header("location: " . $vpb_login_url);
            return false;
        }
         
    }
}